//
//  CinemaTVC.m
//  豆瓣
//
//  Created by lanou3g on 15/12/9.
//  Copyright © 2015年 HaiTeng. All rights reserved.
//

#import "CinemaTVC.h"
#import "CinemaTVCell.h"
#import "CinemaModel.h"
@interface CinemaTVC ()

@property(nonatomic,assign)CGFloat myHeight;

@end

@implementation CinemaTVC



//处理数据
- (instancetype)initWithStyle:(UITableViewStyle)style
{
    if ([super initWithStyle:style]) {
        
        NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"cinemalist" ofType:@"plist"]];
        NSMutableArray *array = dic[@"result"][@"data"];
        self.dataArray = [NSMutableArray array];
        for (NSDictionary *dic in array) {
            CinemaModel *model = [[CinemaModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.dataArray addObject:model];
        }
        
        
        
        
    }
    return self;
}




NSString *cell_id = @"cell_id";


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView.showsVerticalScrollIndicator = NO;
    
    //注册cell
    [self.tableView registerClass:[CinemaTVCell class] forCellReuseIdentifier:cell_id];
    
    
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CinemaTVCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_id forIndexPath:indexPath];
    
    CinemaModel *model = self.dataArray[indexPath.section];
    
    cell.model = model;

    
    
    //自适应高度赋值
    _myHeight = [self getCustomHeight:cell.addressLabel.text];
    cell.addressLabel.frame = CGRectMake(5, 50, cell.bounds.size.width - 10, _myHeight);
    
    
    
    

    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    return _myHeight + 90;
    
}


//自适应高度方法
- (CGFloat)getCustomHeight:(NSString *)str
{
    
    
    
    CGRect rec = [str boundingRectWithSize:CGSizeMake(self.view.bounds.size.width - 10, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:14]} context:nil];
    
    return rec.size.height;
    
}








@end
